# Read in all the F0 contour info. All of these f0.mat files have been downsampled
# in MatLab during linear interpolation (see getf0.mat in the matlab codes)
# matlab code:
# myFolder = '\\client\h$\Desktop\ProsodyPro\m-3-78\channel1';
# myFiles = dir(fullfile(myFolder,'*.wav')); %gets all wav files
#
# for k = 1:length(myFiles)
# baseFileName = myFiles(k).name;
# fullFileName = fullfile(myFolder, baseFileName);
# fprintf(1, 'Now reading %s\n', fullFileName);
# [y, Fs] = audioread(fullFileName);
# [f0, ~] = pitchRocco(y, Fs);
# i = 1:length(f0);
# i_new = linspace(min(i), max(i), 20);
# f0_downsampled = interp1(i, f0, i_new, 'linear');
# fid= fopen(fullfile(myFolder, 'F0.mat'),'a');
# fprintf(fid, '%s ', baseFileName);
# fprintf(fid, '%f ', f0_downsampled);
# fprintf(fid,'\n');
# fclose(fid);
# end
# Step 1: Read in all F0.mat files into f0Files and assign a name for each
f0Files <- lapply(Sys.glob("*/channel1/F0.mat"), read.table)
length(f0Files)
## [1] 15
f0_f_1_78 <- as.data.frame(f0Files[1])
f0_f_1_90 <- as.data.frame(f0Files[2])
f0_f_1_q <- as.data.frame(f0Files[3])
f0_f_2_78 <- as.data.frame(f0Files[4])
f0_f_2_90 <- as.data.frame(f0Files[5])
f0_f_2_q <- as.data.frame(f0Files[6])
f0_m_1_78 <- as.data.frame(f0Files[7])
f0_m_1_90 <- as.data.frame(f0Files[8])
f0_m_1_q <- as.data.frame(f0Files[9])
f0_m_2_78 <- as.data.frame(f0Files[10])
f0_m_2_90 <- as.data.frame(f0Files[11])
f0_m_2_q <- as.data.frame(f0Files[12])
f0_m_3_78 <- as.data.frame(f0Files[13])
f0_m_3_90 <- as.data.frame(f0Files[14])
f0_m_3_q <- as.data.frame(f0Files[15])
# Step 2: Add column names for all dataframes.
numbers <- 1:22
cols <- c("sound.name",numbers)
colnames(f0_f_1_78) <- cols
colnames(f0_f_1_90) <- cols
colnames(f0_f_1_q) <- cols
colnames(f0_f_2_78) <- cols
colnames(f0_f_2_90) <- cols
colnames(f0_f_2_q) <- cols
colnames(f0_m_1_78) <- cols
colnames(f0_m_1_90) <- cols
colnames(f0_m_1_q) <- cols
colnames(f0_m_2_78) <- cols
colnames(f0_m_2_90) <- cols
colnames(f0_m_2_q) <- cols
colnames(f0_m_3_78) <- cols
colnames(f0_m_3_90) <- cols
colnames(f0_m_3_q) <- cols
# Assigning noise level
f0_f_1_78$noise = 78
f0_f_1_90$noise = 90
f0_f_1_q$noise = 0
f0_f_2_78$noise = 78
f0_f_2_90$noise = 90
f0_f_2_q$noise = 0
f0_m_1_78$noise = 78
f0_m_1_90$noise = 90
f0_m_1_q$noise = 0
f0_m_2_78$noise = 78
f0_m_2_90$noise = 90
f0_m_2_q$noise = 0
f0_m_3_78$noise = 78
f0_m_3_90$noise = 90
f0_m_3_q$noise = 0
# Assigning gender variable (0 for female and 1 for male)
f0_f_1_78$gender = 0
f0_f_1_90$gender = 0
f0_f_1_q$gender = 0
f0_f_2_78$gender = 0
f0_f_2_90$gender = 0
f0_f_2_q$gender = 0
f0_m_1_78$gender = 1
f0_m_1_90$gender = 1
f0_m_1_q$gender = 1
f0_m_2_78$gender = 1
f0_m_2_90$gender = 1
f0_m_2_q$gender = 1
f0_m_3_78$gender = 1
f0_m_3_90$gender = 1
f0_m_3_q$gender = 1
### Concatenate all dataframes
f0_reports <- rbind(f0_f_1_78, f0_f_1_90, f0_f_1_q,
f0_f_2_78, f0_f_2_90, f0_f_2_q,
f0_m_1_78, f0_m_1_90, f0_m_1_q,
f0_m_2_78, f0_m_2_90, f0_m_2_q,
f0_m_3_78, f0_m_3_90, f0_m_3_q)
dim(f0_reports)
## [1] 4732 25
According to the report, this dataframe has 4,732 records. In total, from 5 speakers, we have 4732 sound segments to analyze.
# Assign tone values.
# Extracting a substring that contains only the syllable names.
nameswithoutwav <- sapply(strsplit(f0_reports[,1], split=".", fixed=TRUE), "[", 1)
f0_reports$syllable.names <- sapply(strsplit(nameswithoutwav, split="_", fixed=TRUE), "[", 1)
f0_reports$tone <- ifelse(grepl("a", f0_reports$syllable.name, ignore.case=T), "A1",
ifelse(grepl("^tát", f0_reports$syllable.name, ignore.case=T), "D1",
ifelse(grepl("^tạt", f0_reports$syllable.name, ignore.case=T), "D2",
ifelse(grepl("^tết", f0_reports$syllable.name, ignore.case=T), "D1",
ifelse(grepl("^tệt", f0_reports$syllable.name, ignore.case=T), "D2",
ifelse(grepl("^tút", f0_reports$syllable.name, ignore.case=T), "D1",
ifelse(grepl("^tụt", f0_reports$syllable.name, ignore.case=T), "D2",
ifelse(grepl("à", f0_reports$syllable.name, ignore.case=T), "A2",
ifelse(grepl("á", f0_reports$syllable.name, ignore.case=T), "B1",
ifelse(grepl("ả", f0_reports$syllable.name, ignore.case=T), "C1",
ifelse(grepl("ã", f0_reports$syllable.name, ignore.case=T), "C2",
ifelse(grepl("ạ", f0_reports$syllable.name, ignore.case=T), "B2",
ifelse(grepl("ê", f0_reports$syllable.name, ignore.case=T), "A1",
ifelse(grepl("ề", f0_reports$syllable.name, ignore.case=T), "A2",
ifelse(grepl("ế", f0_reports$syllable.name, ignore.case=T), "B1",
ifelse(grepl("ể", f0_reports$syllable.name, ignore.case=T), "C1",
ifelse(grepl("ễ", f0_reports$syllable.name, ignore.case=T), "C2",
ifelse(grepl("ệ", f0_reports$syllable.name, ignore.case=T), "B2",
ifelse(grepl("u", f0_reports$syllable.name, ignore.case=T), "A1",
ifelse(grepl("ù", f0_reports$syllable.name, ignore.case=T), "A2",
ifelse(grepl("ú", f0_reports$syllable.name, ignore.case=T), "B1",
ifelse(grepl("ủ", f0_reports$syllable.name, ignore.case=T), "C1",
ifelse(grepl("ũ", f0_reports$syllable.name, ignore.case=T), "C2",
ifelse(grepl("ụ", f0_reports$syllable.name, ignore.case=T), "B2",
ifelse(grepl("ộ", f0_reports$syllable.name, ignore.case=T), "B2","NA")))))))))))))))))))))))))
# Assigning if the token is single (1) or not (0). Single tokens were produced in isolation.
# Otherwise they were produced in carrier sentences.
f0_reports$single <- ifelse(grepl("single", f0_reports$sound.name), 1, 0)
# Convert categorical variables to factor levels.
f0_reports$gender <- as.factor(f0_reports$gender)
f0_reports$single <- as.factor(f0_reports$single)
f0_reports$tone <- as.factor(f0_reports$tone)
f0_reports$noise <- as.factor(f0_reports$noise)
summary(f0_reports)
## sound.name 1 2 3
## Length:4732 Min. : 0.0 Min. : 0.0 Min. : 0.0
## Class :character 1st Qu.: 0.0 1st Qu.:120.8 1st Qu.:128.6
## Mode :character Median :125.7 Median :150.8 Median :155.8
## Mean :108.1 Mean :148.2 Mean :158.4
## 3rd Qu.:167.5 3rd Qu.:190.9 3rd Qu.:194.2
## Max. :376.5 Max. :353.5 Max. :369.9
##
## 4 5 6 7
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.:130.0 1st Qu.:129.5 1st Qu.:128.0 1st Qu.:125.6
## Median :157.5 Median :158.2 Median :157.7 Median :156.3
## Mean :161.2 Mean :161.1 Mean :160.1 Mean :157.7
## 3rd Qu.:194.3 3rd Qu.:193.4 3rd Qu.:192.2 3rd Qu.:190.5
## Max. :355.8 Max. :320.7 Max. :310.0 Max. :304.2
##
## 8 9 10 11
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.:123.9 1st Qu.:121.8 1st Qu.:120.3 1st Qu.:119.1
## Median :154.9 Median :154.2 Median :153.8 Median :153.3
## Mean :155.9 Mean :154.4 Mean :154.2 Mean :153.1
## 3rd Qu.:188.7 3rd Qu.:187.5 3rd Qu.:187.2 3rd Qu.:187.1
## Max. :311.4 Max. :346.5 Max. :320.2 Max. :307.4
##
## 12 13 14 15
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.:117.4 1st Qu.:116.1 1st Qu.:114.8 1st Qu.:113.2
## Median :152.4 Median :152.3 Median :152.0 Median :151.9
## Mean :152.3 Mean :150.9 Mean :150.3 Mean :150.2
## 3rd Qu.:186.9 3rd Qu.:187.2 3rd Qu.:187.8 3rd Qu.:188.8
## Max. :311.6 Max. :318.9 Max. :325.3 Max. :332.6
##
## 16 17 18 19
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.:112.0 1st Qu.:110.1 1st Qu.:109.9 1st Qu.:108.2
## Median :151.5 Median :150.7 Median :151.1 Median :149.7
## Mean :149.8 Mean :149.7 Mean :149.7 Mean :147.4
## 3rd Qu.:190.3 3rd Qu.:192.4 3rd Qu.:194.2 3rd Qu.:193.4
## Max. :339.4 Max. :393.9 Max. :406.0 Max. :428.0
##
## 20 21 22 noise gender
## Min. : 0.0 Min. : 0.00 Min. : 0.00 0 :1575 0:1893
## 1st Qu.:103.8 1st Qu.: 95.53 1st Qu.: 0.00 78:1578 1:2839
## Median :144.3 Median :133.69 Median : 89.51 90:1579
## Mean :142.3 Mean :131.34 Mean : 79.14
## 3rd Qu.:190.7 3rd Qu.:182.09 3rd Qu.:138.13
## Max. :413.7 Max. :377.12 Max. :343.06
##
## syllable.names tone single
## Length:4732 B2 :780 0:2366
## Class :character A2 :719 1:2366
## Mode :character B1 :719
## C1 :719
## C2 :719
## A1 :716
## (Other):360
# Note that I only plot the 2nd to 19th sampled points.
# Extract F0 of all tones A1 (574 instances)
par(mfrow=c(2,4))
A1 <- data.matrix(f0_reports[f0_reports$tone=="A1",-c(1,c(22:26))])
plot(colMeans(A1)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 200))
# # Do the same for the other tones
A2 <- data.matrix(f0_reports[f0_reports$tone=="A2",-c(1,c(22:26))])
plot(colMeans(A2)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 200))
B1 <- data.matrix(f0_reports[f0_reports$tone=="B1",-c(1,c(22:26))])
plot(colMeans(B1)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 200))
B2 <- data.matrix(f0_reports[f0_reports$tone=="B2",-c(1,c(22:26))])
plot(colMeans(B2)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 250))
C1 <- data.matrix(f0_reports[f0_reports$tone=="C1",-c(1,c(22:26))])
plot(colMeans(C1)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 250))
C2 <- data.matrix(f0_reports[f0_reports$tone=="C2",-c(1,c(22:26))])
plot(colMeans(C2)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 250))
D1 <- data.matrix(f0_reports[f0_reports$tone=="D1",-c(1,c(22:26))])
plot(colMeans(D1)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 250))
D2 <- data.matrix(f0_reports[f0_reports$tone=="D2",-c(1,c(22:26))])
plot(colMeans(D2)[3:18], type="l", xlim=c(1, 18), ylim=c(60, 250))
plot(colMeans(A1)[3:18], type="b", xlim=c(1, 18), ylim=c(60, 200), xlab="Sampling points", ylab="F0 (Hz)")
lines(colMeans(A2)[3:18],col="green", type="b", pch=19)
lines(colMeans(B1)[3:18],col="red", type="b", pch=19)
lines(colMeans(B2)[3:18],col="purple", type="b", pch=19)
lines(colMeans(C1)[3:18],col="blue", type="b", pch=19)
lines(colMeans(C2)[3:18],col="orange", type="b", pch=19)
# Add a legend
legend(1, 100, legend=c("A1", "A2", "B1", "B2", "C1", "C2"),
col=c("black", "green", "red", "purple", "blue", "orange"), lty=1:2, cex=0.7)
Plot B1, B2, D1, D2 together.
plot(colMeans(B1)[3:18], type="b", col="blue", xlim=c(1, 18), ylim=c(60, 220), , xlab="Sampling points", ylab="F0 (Hz)")
lines(colMeans(B2)[3:18],col="purple", type="b", pch=19)
lines(colMeans(D1)[3:18],col="pink", type="b", pch=19) ## D1 has a very strange contour.
lines(colMeans(D2)[3:18],col="black", type="b", pch=19)
# Add a legend
legend(1, 100, legend=c("B1", "B2", "D1", "D2"),
col=c("blue", "orange", "pink", "black"), lty=1:2, cex=0.7)
regression_report <- function(tone) {
lm_tone <- lm(colMeans(tone)[3:18]~ c(1:16))
plot(colMeans(tone)[3:18], pch = 16, cex = 1.3, xlim=c(1, 18), ylim=c(60, 250))
abline(lm(colMeans(tone)[3:18] ~ c(1:16)))
return(lm_tone)
}
## Call regression_report on all tones.
regression_report(A1)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 174.5199 -0.3935
regression_report(A2)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 153.905 -1.488
regression_report(B1)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 133.061 2.715
regression_report(B2)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 188.405 -5.683
regression_report(C1)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 161.437 -3.094
regression_report(C2)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 152.882 2.769
regression_report(D1)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 172.535 2.251
regression_report(D2)
##
## Call:
## lm(formula = colMeans(tone)[3:18] ~ c(1:16))
##
## Coefficients:
## (Intercept) c(1:16)
## 161.581 -1.977
# Plot F0 contours according to different levels
filter_f0 <- function(tone, noise, s) {
if (s==TRUE) {
tone_matrix <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise==noise & f0_reports$single=="1",-c(1,c(22:26))])
return(tone_matrix)
} else {
tone_matrix <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise==noise & f0_reports$single=="0",-c(1,c(22:26))])
return(tone_matrix)
}
}
plot_f0_by_noise <- function(tone, s) {
if (s==TRUE) {
tone_quiet <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="0" & f0_reports$single=="1",-c(1,c(22:26))])
tone_78 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="78" & f0_reports$single=="1",-c(1,c(22:26))])
tone_90 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="90" & f0_reports$single=="1",-c(1,c(22:26))])
plot(colMeans(tone_quiet)[3:18], type="l", xlim=c(1, 18), ylim=c(70, 250), xlab="Sampling points", ylab=paste("F0 for single tokens, tone", tone))
lines(colMeans(tone_78)[3:18],col="blue")
lines(colMeans(tone_90)[3:18],col="red")
legend(1, 100, legend=c("quiet", "78dB", "90dB"),
col=c("black", "blue", "red"), lty=1:2, cex=0.7)
# Find regression coefficients and return them.
c(summary(regression_report(tone_quiet))$coefficients[2,1], summary(regression_report(tone_78))$coefficients[2,1], summary(regression_report(tone_90))$coefficients[2,1])
} else {
tone_quiet <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="0" & f0_reports$single=="0",-c(1,c(22:26))])
tone_78 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="78" & f0_reports$single=="0",-c(1,c(22:26))])
tone_90 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="90" & f0_reports$single=="0",-c(1,c(22:26))])
plot(colMeans(tone_quiet)[3:18], type="l", xlim=c(1, 18), ylim=c(70, 250), xlab="Sampling points", ylab=paste("F0 for tokens in carrier, tone", tone))
lines(colMeans(tone_78)[3:18],col="blue")
lines(colMeans(tone_90)[3:18],col="red")
legend(1, 100, legend=c("quiet", "78dB", "90dB"),
col=c("black", "blue", "red"), lty=1:2, cex=0.7)
c(summary(regression_report(tone_quiet))$coefficients[2,1], summary(regression_report(tone_78))$coefficients[2,1], summary(regression_report(tone_90))$coefficients[2,1])
}
}
coefficient_reports <- function(tone_matrix) {
lm_model <- lm(colMeans(tone_matrix)[3:18] ~ c(1:16))
summary(lm_model)$coefficients[2,1]
}
plot_f0_by_noise("A1", TRUE)
## [1] -0.3186279 -0.8063768 -0.2594854
plot_f0_by_noise("A2",TRUE)
## [1] -1.249683 -1.800296 -1.714919
plot_f0_by_noise("B1", TRUE)
## [1] 2.309495 4.016975 5.183039
plot_f0_by_noise("B2",TRUE)
## [1] -2.261342 -6.841648 -7.033730
plot_f0_by_noise("C1",TRUE)
## [1] -1.441349 -2.268266 -2.558085
###F0 and regression line for tone C2, single tokens.
plot_f0_by_noise("C2", TRUE)
## [1] 3.599173 4.000898 4.149219
plot_f0_by_noise("D1",TRUE)
## [1] 1.008148 4.267634 2.505821
plot_f0_by_noise("D2", TRUE)
## [1] -1.386405 -3.235499 -1.578594
plot_f0_by_noise("A1", FALSE)
## [1] -0.4473569 -0.2207056 -0.3135566
plot_f0_by_noise("A2",FALSE)
## [1] -1.230934 -1.359417 -1.564121
plot_f0_by_noise("B1", FALSE)
## [1] 1.498756 1.660200 1.619737
plot_f0_by_noise("B2",FALSE)
## [1] -4.028040 -5.994461 -7.936588
plot_f0_by_noise("C1",FALSE)
## [1] -3.147131 -4.021417 -5.136960
plot_f0_by_noise("C2", FALSE)
## [1] 1.337868 1.872823 1.661997
plot_f0_by_noise("D1",FALSE)
## [1] 2.352847 1.723309 1.646091
plot_f0_by_noise("D2", FALSE)
## [1] -2.344592 -1.936387 -1.382912
# Table of tone * noise (20x3)
tab <- matrix(,nrow=16, ncol=3, byrow=TRUE)
colnames(tab) <- c('quiet','noise 78','noise 90')
rownames(tab) <- c('A1 single','A2 single','B1 single', 'B2 single',
'C1 single','C2 single','D1 single', 'D2 single',
'A1 carrier','A2 carrier','B1 carrier', 'B2 carrier',
'C1 carrier','C2 carrier','D1 carrier', 'D2 carrier')
tab <- as.table(tab)
tab[1,1] = coefficient_reports(filter_f0("A1", "0", TRUE))
tab[1,2] = coefficient_reports(filter_f0("A1", "78", TRUE))
tab[1,3] = coefficient_reports(filter_f0("A1", "90", TRUE))
tab[2,1] = coefficient_reports(filter_f0("A2", "0", TRUE))
tab[2,2] = coefficient_reports(filter_f0("A2", "78", TRUE))
tab[2,3] = coefficient_reports(filter_f0("A2", "90", TRUE))
tab[3,1] = coefficient_reports(filter_f0("B1", "0", TRUE))
tab[3,2] = coefficient_reports(filter_f0("B1", "78", TRUE))
tab[3,3] = coefficient_reports(filter_f0("B1", "90", TRUE))
tab[4,1] = coefficient_reports(filter_f0("B2", "0", TRUE))
tab[4,2] = coefficient_reports(filter_f0("B2", "78", TRUE))
tab[4,3] = coefficient_reports(filter_f0("B2", "90", TRUE))
tab[5,1] = coefficient_reports(filter_f0("C1", "0", TRUE))
tab[5,2] = coefficient_reports(filter_f0("C1", "78", TRUE))
tab[5,3] = coefficient_reports(filter_f0("C1", "90", TRUE))
tab[6,1] = coefficient_reports(filter_f0("C2", "0", TRUE))
tab[6,2] = coefficient_reports(filter_f0("C2", "78", TRUE))
tab[6,3] = coefficient_reports(filter_f0("C2", "90", TRUE))
tab[7,1] = coefficient_reports(filter_f0("D1", "0", TRUE))
tab[7,2] = coefficient_reports(filter_f0("D1", "78", TRUE))
tab[7,3] = coefficient_reports(filter_f0("D1", "90", TRUE))
tab[8,1] = coefficient_reports(filter_f0("D2", "0", TRUE))
tab[8,2] = coefficient_reports(filter_f0("D2", "78", TRUE))
tab[8,3] = coefficient_reports(filter_f0("D2", "90", TRUE))
# carrier
tab[9,1] = coefficient_reports(filter_f0("A1", "0", FALSE))
tab[9,2] = coefficient_reports(filter_f0("A1", "78", FALSE))
tab[9,3] = coefficient_reports(filter_f0("A1", "90", FALSE))
tab[10,1] = coefficient_reports(filter_f0("A2", "0", FALSE))
tab[10,2] = coefficient_reports(filter_f0("A2", "78", FALSE))
tab[10,3] = coefficient_reports(filter_f0("A2", "90", FALSE))
tab[11,1] = coefficient_reports(filter_f0("B1", "0", FALSE))
tab[11,2] = coefficient_reports(filter_f0("B1", "78", FALSE))
tab[11,3] = coefficient_reports(filter_f0("B1", "90", FALSE))
tab[12,1] = coefficient_reports(filter_f0("B2", "0", FALSE))
tab[12,2] = coefficient_reports(filter_f0("B2", "78", FALSE))
tab[12,3] = coefficient_reports(filter_f0("B2", "90", FALSE))
tab[13,1] = coefficient_reports(filter_f0("C1", "0", FALSE))
tab[13,2] = coefficient_reports(filter_f0("C1", "78", FALSE))
tab[13,3] = coefficient_reports(filter_f0("C1", "90", FALSE))
tab[14,1] = coefficient_reports(filter_f0("C2", "0", FALSE))
tab[14,2] = coefficient_reports(filter_f0("C2", "78", FALSE))
tab[14,3] = coefficient_reports(filter_f0("C2", "90", FALSE))
tab[15,1] = coefficient_reports(filter_f0("D1", "0", FALSE))
tab[15,2] = coefficient_reports(filter_f0("D1", "78", FALSE))
tab[15,3] = coefficient_reports(filter_f0("D1", "90", FALSE))
tab[16,1] = coefficient_reports(filter_f0("D2", "0", FALSE))
tab[16,2] = coefficient_reports(filter_f0("D2", "78", FALSE))
tab[16,3] = coefficient_reports(filter_f0("D2", "90", FALSE))
print(tab)
## quiet noise 78 noise 90
## A1 single -0.3186279 -0.8063768 -0.2594854
## A2 single -1.2496828 -1.8002956 -1.7149195
## B1 single 2.3094951 4.0169749 5.1830386
## B2 single -2.2613416 -6.8416476 -7.0337297
## C1 single -1.4413495 -2.2682665 -2.5580854
## C2 single 3.5991729 4.0008982 4.1492188
## D1 single 1.0081479 4.2676344 2.5058210
## D2 single -1.3864047 -3.2354986 -1.5785943
## A1 carrier -0.4473569 -0.2207056 -0.3135566
## A2 carrier -1.2309338 -1.3594174 -1.5641211
## B1 carrier 1.4987565 1.6602000 1.6197374
## B2 carrier -4.0280404 -5.9944606 -7.9365880
## C1 carrier -3.1471313 -4.0214169 -5.1369596
## C2 carrier 1.3378682 1.8728228 1.6619970
## D1 carrier 2.3528466 1.7233088 1.6460912
## D2 carrier -2.3445924 -1.9363866 -1.3829121
# Add vowel annotation.
f0_reports$vowel <- ifelse(grepl("a", f0_reports$syllable.name, ignore.case=T), "A",
ifelse(grepl("à", f0_reports$syllable.name, ignore.case=T), "A",
ifelse(grepl("á", f0_reports$syllable.name, ignore.case=T), "A",
ifelse(grepl("ả", f0_reports$syllable.name, ignore.case=T), "A",
ifelse(grepl("ã", f0_reports$syllable.name, ignore.case=T), "A",
ifelse(grepl("ạ", f0_reports$syllable.name, ignore.case=T), "A",
ifelse(grepl("ê", f0_reports$syllable.name, ignore.case=T), "E",
ifelse(grepl("ề", f0_reports$syllable.name, ignore.case=T), "E",
ifelse(grepl("ế", f0_reports$syllable.name, ignore.case=T), "E",
ifelse(grepl("ể", f0_reports$syllable.name, ignore.case=T), "E",
ifelse(grepl("ễ", f0_reports$syllable.name, ignore.case=T), "E",
ifelse(grepl("ệ", f0_reports$syllable.name, ignore.case=T), "E",
ifelse(grepl("u", f0_reports$syllable.name, ignore.case=T), "U",
ifelse(grepl("ù", f0_reports$syllable.name, ignore.case=T), "U",
ifelse(grepl("ú", f0_reports$syllable.name, ignore.case=T), "U",
ifelse(grepl("ủ", f0_reports$syllable.name, ignore.case=T), "U",
ifelse(grepl("ũ", f0_reports$syllable.name, ignore.case=T), "U",
ifelse(grepl("ụ", f0_reports$syllable.name, ignore.case=T), "U",
ifelse(grepl("ộ", f0_reports$syllable.name, ignore.case=T), "O","NA")))))))))))))))))))
# Convert vowel types to a factor variable
f0_reports$vowel <- as.factor(f0_reports$vowel)
head(f0_reports, 30)
# Plot F0 contour by vowels (not distinguishing single tokens or tokens in carriers.)
plot_f0_by_vowels <- function(tone, vowel) {
if (vowel=="A") {
tone_quiet <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="0" & f0_reports$vowel=="A",-c(1,c(22:26))])
tone_78 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="78" & f0_reports$vowel=="A",-c(1,c(22:26))])
tone_90 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="90" & f0_reports$vowel=="A",-c(1,c(22:26))])
plot(colMeans(tone_quiet)[3:18], type="l", xlim=c(1, 18), ylim=c(70, 250), xlab="Sampling points", ylab=paste("F0 for vowel A, tone", tone))
lines(colMeans(tone_78)[3:18],col="blue")
lines(colMeans(tone_90)[3:18],col="red")
# Find regression coefficients and return them.
c(summary(regression_report(tone_quiet))$coefficients[2,1], summary(regression_report(tone_78))$coefficients[2,1], summary(regression_report(tone_90))$coefficients[2,1])
} else if (vowel=="E") {
tone_quiet <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="0" & f0_reports$vowel=="E",-c(1,c(22:26))])
tone_78 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="78" & f0_reports$vowel=="E",-c(1,c(22:26))])
tone_90 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="90" & f0_reports$vowel=="E",-c(1,c(22:26))])
plot(colMeans(tone_quiet)[3:18], type="l", xlim=c(1, 18), ylim=c(70, 250), xlab="Sampling points", ylab=paste("F0 for vowel E, tone", tone))
lines(colMeans(tone_78)[3:18],col="blue")
lines(colMeans(tone_90)[3:18],col="red")
# Find regression coefficients and return them.
c(summary(regression_report(tone_quiet))$coefficients[2,1], summary(regression_report(tone_78))$coefficients[2,1], summary(regression_report(tone_90))$coefficients[2,1])
} else {
tone_quiet <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="0" & f0_reports$vowel=="U",-c(1,c(22:26))])
tone_78 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="78" & f0_reports$vowel=="U",-c(1,c(22:26))])
tone_90 <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise=="90" & f0_reports$vowel=="U",-c(1,c(22:26))])
plot(colMeans(tone_quiet)[3:18], type="l", xlim=c(1, 18), ylim=c(70, 250), xlab="Sampling points", ylab=paste("F0 for vowel U, tone", tone))
lines(colMeans(tone_78)[3:18],col="blue")
lines(colMeans(tone_90)[3:18],col="red")
# Find regression coefficients and return them.
c(summary(regression_report(tone_quiet))$coefficients[2,1], summary(regression_report(tone_78))$coefficients[2,1], summary(regression_report(tone_90))$coefficients[2,1])
}
}
# Call functions
plot_f0_by_vowels("A1", "A")
## [1] -0.14690974 -0.31942091 -0.04571527
plot_f0_by_vowels("A1", "E")
## [1] -0.1059034 -0.7318152 -0.4137195
plot_f0_by_vowels("A1", "U")
## [1] -0.8940176 -0.4878123 -0.4001283
plot_f0_by_vowels("A2", "A")
## [1] -0.9017129 -1.4478054 -1.3585915
plot_f0_by_vowels("A2", "E")
## [1] -1.185626 -1.632257 -1.589951
plot_f0_by_vowels("A2", "U")
## [1] -1.628670 -1.662941 -1.967450
plot_f0_by_vowels("B1", "A")
## [1] 2.119938 2.604628 3.487482
plot_f0_by_vowels("B1", "E")
## [1] 2.708719 3.422099 3.781400
plot_f0_by_vowels("B1", "U")
## [1] 0.8656728 2.4890358 2.9352821
plot_f0_by_vowels("B2", "A")
## [1] -3.490682 -6.213033 -6.798165
plot_f0_by_vowels("B2", "E")
## [1] -2.557656 -7.188424 -7.862296
plot_f0_by_vowels("B2", "U")
## [1] -3.391056 -6.207349 -7.806966
plot_f0_by_vowels("C1", "A")
## [1] -2.062575 -2.701781 -3.125616
plot_f0_by_vowels("C1", "E")
## [1] -2.456957 -2.901117 -4.098411
plot_f0_by_vowels("C1", "U")
## [1] -2.363189 -3.815132 -4.318540
plot_f0_by_vowels("C2", "A")
## [1] 2.782585 3.233750 3.529397
plot_f0_by_vowels("C2", "E")
## [1] 2.869950 2.970794 2.871590
plot_f0_by_vowels("C2", "U")
## [1] 1.742820 2.606038 2.315837
plot_f0_by_vowels("D1", "A")
## [1] 2.442698 2.203181 2.117786
plot_f0_by_vowels("D1", "E")
## [1] 1.994048 4.776254 3.414007
plot_f0_by_vowels("D1", "U")
## [1] 0.6047457 2.0069804 0.6960755
plot_f0_by_vowels("D2", "A")
## [1] -1.348073 -3.284115 -1.984973
plot_f0_by_vowels("D2", "E")
## [1] -0.9056471 -1.9051956 -0.7953201
plot_f0_by_vowels("D2", "U")
## [1] -3.342776 -2.568517 -1.661967
filter_f0 <- function(tone, vowel, noise) {
tone_matrix <- data.matrix(f0_reports[f0_reports$tone==tone & f0_reports$noise==noise & f0_reports$vowel==vowel,-c(1,c(22:26))])
return(tone_matrix)
}
# Table of tone * noise (24x3)
tab_vowel <- matrix(,nrow=24, ncol=3, byrow=TRUE)
colnames(tab_vowel) <- c('quiet','noise 78','noise 90')
rownames(tab_vowel) <- c('A1 A','A2 A','B1 A', 'B2 A',
'C1 A','C2 A','D1 A', 'D2 A',
'A1 E','A2 E','B1 E', 'B2 E',
'C1 E','C2 E','D1 E', 'D2 E',
'A1 U','A2 U','B1 U', 'B2 U',
'C1 U','C2 U','D1 U', 'D2 U')
tab_vowel <- as.table(tab_vowel)
tab_vowel[1,1] = coefficient_reports(filter_f0("A1", "A", "0"))
tab_vowel[1,2] = coefficient_reports(filter_f0("A1", "A", "78"))
tab_vowel[1,3] = coefficient_reports(filter_f0("A1", "A", "90"))
tab_vowel[2,1] = coefficient_reports(filter_f0("A2", "A", "0"))
tab_vowel[2,2] = coefficient_reports(filter_f0("A2", "A", "78"))
tab_vowel[2,3] = coefficient_reports(filter_f0("A2", "A", "90"))
tab_vowel[3,1] = coefficient_reports(filter_f0("B1", "A", "0"))
tab_vowel[3,2] = coefficient_reports(filter_f0("B1", "A", "78"))
tab_vowel[3,3] = coefficient_reports(filter_f0("B1", "A", "90"))
tab_vowel[4,1] = coefficient_reports(filter_f0("B2", "A", "0"))
tab_vowel[4,2] = coefficient_reports(filter_f0("B2", "A", "78"))
tab_vowel[4,3] = coefficient_reports(filter_f0("B2", "A", "90"))
tab_vowel[5,1] = coefficient_reports(filter_f0("C1", "A", "0"))
tab_vowel[5,2] = coefficient_reports(filter_f0("C1", "A", "78"))
tab_vowel[5,3] = coefficient_reports(filter_f0("C1", "A", "90"))
tab_vowel[6,1] = coefficient_reports(filter_f0("C2", "A", "0"))
tab_vowel[6,2] = coefficient_reports(filter_f0("C2", "A", "78"))
tab_vowel[6,3] = coefficient_reports(filter_f0("C2", "A", "90"))
tab_vowel[7,1] = coefficient_reports(filter_f0("D1", "A", "0"))
tab_vowel[7,2] = coefficient_reports(filter_f0("D1", "A", "78"))
tab_vowel[7,3] = coefficient_reports(filter_f0("D1", "A", "90"))
tab_vowel[8,1] = coefficient_reports(filter_f0("D2", "A", "0"))
tab_vowel[8,2] = coefficient_reports(filter_f0("D2", "A", "78"))
tab_vowel[8,3] = coefficient_reports(filter_f0("D2", "A", "90"))
tab_vowel[9,1] = coefficient_reports(filter_f0("A1", "E", "0"))
tab_vowel[9,2] = coefficient_reports(filter_f0("A1", "E", "78"))
tab_vowel[9,3] = coefficient_reports(filter_f0("A1", "E", "90"))
tab_vowel[10,1] = coefficient_reports(filter_f0("A2", "E", "0"))
tab_vowel[10,2] = coefficient_reports(filter_f0("A2", "E", "78"))
tab_vowel[10,3] = coefficient_reports(filter_f0("A2", "E", "90"))
tab_vowel[11,1] = coefficient_reports(filter_f0("B1", "E", "0"))
tab_vowel[11,2] = coefficient_reports(filter_f0("B1", "E", "78"))
tab_vowel[11,3] = coefficient_reports(filter_f0("B1", "E", "90"))
tab_vowel[12,1] = coefficient_reports(filter_f0("B2", "E", "0"))
tab_vowel[12,2] = coefficient_reports(filter_f0("B2", "E", "78"))
tab_vowel[12,3] = coefficient_reports(filter_f0("B2", "E", "90"))
tab_vowel[13,1] = coefficient_reports(filter_f0("C1", "E", "0"))
tab_vowel[13,2] = coefficient_reports(filter_f0("C1", "E", "78"))
tab_vowel[13,3] = coefficient_reports(filter_f0("C1", "E", "90"))
tab_vowel[14,1] = coefficient_reports(filter_f0("C2", "E", "0"))
tab_vowel[14,2] = coefficient_reports(filter_f0("C2", "E", "78"))
tab_vowel[14,3] = coefficient_reports(filter_f0("C2", "E", "90"))
tab_vowel[15,1] = coefficient_reports(filter_f0("D1", "E", "0"))
tab_vowel[15,2] = coefficient_reports(filter_f0("D1", "E", "78"))
tab_vowel[15,3] = coefficient_reports(filter_f0("D1", "E", "90"))
tab_vowel[16,1] = coefficient_reports(filter_f0("D2", "E", "0"))
tab_vowel[16,2] = coefficient_reports(filter_f0("D2", "E", "78"))
tab_vowel[16,3] = coefficient_reports(filter_f0("D2", "E", "90"))
tab_vowel[17,1] = coefficient_reports(filter_f0("A1", "U", "0"))
tab_vowel[17,2] = coefficient_reports(filter_f0("A1", "U", "78"))
tab_vowel[17,3] = coefficient_reports(filter_f0("A1", "U", "90"))
tab_vowel[18,1] = coefficient_reports(filter_f0("A2", "U", "0"))
tab_vowel[18,2] = coefficient_reports(filter_f0("A2", "U", "78"))
tab_vowel[18,3] = coefficient_reports(filter_f0("A2", "U", "90"))
tab_vowel[19,1] = coefficient_reports(filter_f0("B1", "U", "0"))
tab_vowel[19,2] = coefficient_reports(filter_f0("B1", "U", "78"))
tab_vowel[19,3] = coefficient_reports(filter_f0("B1", "U", "90"))
tab_vowel[20,1] = coefficient_reports(filter_f0("B2", "U", "0"))
tab_vowel[20,2] = coefficient_reports(filter_f0("B2", "U", "78"))
tab_vowel[20,3] = coefficient_reports(filter_f0("B2", "U", "90"))
tab_vowel[21,1] = coefficient_reports(filter_f0("C1", "U", "0"))
tab_vowel[21,2] = coefficient_reports(filter_f0("C1", "U", "78"))
tab_vowel[21,3] = coefficient_reports(filter_f0("C1", "U", "90"))
tab_vowel[22,1] = coefficient_reports(filter_f0("C2", "U", "0"))
tab_vowel[22,2] = coefficient_reports(filter_f0("C2", "U", "78"))
tab_vowel[22,3] = coefficient_reports(filter_f0("C2", "U", "90"))
tab_vowel[23,1] = coefficient_reports(filter_f0("D1", "U", "0"))
tab_vowel[23,2] = coefficient_reports(filter_f0("D1", "U", "78"))
tab_vowel[23,3] = coefficient_reports(filter_f0("D1", "U", "90"))
tab_vowel[24,1] = coefficient_reports(filter_f0("D2", "U", "0"))
tab_vowel[24,2] = coefficient_reports(filter_f0("D2", "U", "78"))
tab_vowel[24,3] = coefficient_reports(filter_f0("D2", "U", "90"))
tab_vowel
## quiet noise 78 noise 90
## A1 A -0.14690974 -0.31942091 -0.04571527
## A2 A -0.90171287 -1.44780542 -1.35859145
## B1 A 2.11993763 2.60462774 3.48748176
## B2 A -3.49068222 -6.21303338 -6.79816521
## C1 A -2.06257542 -2.70178090 -3.12561635
## C2 A 2.78258485 3.23374956 3.52939673
## D1 A 2.44269826 2.20318071 2.11778582
## D2 A -1.34807296 -3.28411482 -1.98497265
## A1 E -0.10590344 -0.73181521 -0.41371947
## A2 E -1.18562586 -1.63225715 -1.58995052
## B1 E 2.70871905 3.42209873 3.78140019
## B2 E -2.55765621 -7.18842448 -7.86229611
## C1 E -2.45695674 -2.90111675 -4.09841124
## C2 E 2.86994985 2.97079352 2.87158994
## D1 E 1.99404772 4.77625367 3.41400699
## D2 E -0.90564712 -1.90519561 -0.79532005
## A1 U -0.89401759 -0.48781233 -0.40012832
## A2 U -1.62867033 -1.66294086 -1.96744978
## B1 U 0.86567285 2.48903582 2.93528206
## B2 U -3.39105587 -6.20734889 -7.80696569
## C1 U -2.36318903 -3.81513202 -4.31853990
## C2 U 1.74281972 2.60603842 2.31583707
## D1 U 0.60474574 2.00698042 0.69607554
## D2 U -3.34277554 -2.56851738 -1.66196690